import 'package:cat_eye/base/base_refresh_state.dart';
import 'package:cat_eye/base/base_refresh_view_model.dart';
import 'package:cat_eye/base/base_view_model.dart';
import 'package:cat_eye/bean/sq_lite_bean.dart';
import 'package:cat_eye/config/color_config.dart';
import 'package:cat_eye/config/string_config.dart';
import 'package:cat_eye/root_page/hot_page/hot_list_widget.dart';
import 'package:cat_eye/sqflite/sqLite_manager.dart';
import 'package:cat_eye/util/util.dart';
import 'package:cat_eye/view_model/hot_view_model/hot_view_model.dart';
import 'package:flutter/material.dart';

/*
* @Package: home_page
* @ClassName: hot_page
* @Author: szj
* @CreateDate: 7/28/21 1:22 PM
* TODO 热门页面
*/
class HotPageWidget extends StatefulWidget {
  const HotPageWidget({Key key}) : super(key: key);

  @override
  _HotPageWidgetState createState() => _HotPageWidgetState();
}

class _HotPageWidgetState extends BaseRefreshState<HotPageWidget, HotViewModel>
    with SingleTickerProviderStateMixin {
  List<SqLiteBean> list = [];

  @override
  HotViewModel get buildViewModel => HotViewModel();

  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: 3);
  }

  @override
  Widget buildWidget(BuildContext context, HotViewModel model) {
    return Scaffold(
      appBar: appBar(
        StringConfig.POPULARITY_LIST,
        //主题颜色
        backgroundColor: ColorConfig.themeColor,
        bottom: TabBar(
          //可滑动
          isScrollable: true,
          //TabBar和TabBarView controller 必须统一
          controller: _tabController,
          //字体颜色
          labelColor: Colors.black,
          //滑动条颜色
          indicatorColor: themeColor(),
          tabs: model.tabList.map((e) => Tab(text: e.name)).toList(),
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children:
            model.tabList.map((e) => HotListWidget(url: e.apiUrl)).toList(),
      ),
    );
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }
}
